package com.pg_chat.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebsocketConfig implements WebSocketMessageBrokerConfigurer {

    //设置通信头
   @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/endpoint")
                .setAllowedOrigins("*")
                .withSockJS();
    }

    @Override
   public void configureMessageBroker(MessageBrokerRegistry registry) {
       // / /topic 系统广播消息 /group 群消息
        registry.enableSimpleBroker("/topic"
                ,"/group");

        //点对点使用的订阅前缀（客户端订阅路径上会体现出来），不设置的话，默认也是
        //registry.setUserDestinationPrefix("/");
   }
}
